<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    //手写forEach
   Array.prototype.myForEach= function (fn){
     for(let i=0;i<this.length;i++){
      fn(this[i],i,this)
     }
    }
    const arr=[1,2,3,4,5,6]
    arr.myForEach((item,index,array)=>{
    })

    

    //手写map
    Array.prototype.myMap=function(fn){
    const arr=[]
     for(let i=0;i<this.length;i++){
     arr.push(fn(this[i],i,this));
     }
     return arr
    }
    // console.log(arr.myMap((item,index)=>{
    //   return ++item
    // }));
   



    //手写filter
    Array.prototype.myFilter=function(fn){
      const arr=[]
      for(let i=0;i<this.length;i++){
     fn(this[i],i,this) && arr.push(this[i])
      }
      return arr
    }

    // console.log(arr.myFilter(item=>{
    //   return item>4
    // }));



    //手写reduce 
    Array.prototype.myReduce=function(fn,a){
     let prev=a===undefined?this[0]:a
    for(let i=a===undefined?1:0;i<this.length;i++){
      prev=fn(prev,this[i],i,this)
    }
      return prev
    }
   console.log( arr.myReduce((prev,item)=>{
        return prev+item
    }));





    //手写find
    Array.prototype.myFind=function(fn){
      for(let i=0;i<this.length;i++){
      if(fn(this[i],i,this)){
        return this[i]
      }
      }
    }
  // console.log(arr.myFind(item=>{
  //   return item>4
  //   }));  




    //手写findindex
    Array.prototype.myFindindex=function(fn){
      for(let i=0;i<this.length;i++){
      if(fn(this[i],i,this)){
        return i
      }
      }
    }
  // console.log(arr.myFindindex(item=>{
  //   return item>4
  //   }));  



    //手写inclues
    Array.prototype.myIncludes=function(a){
      for(let i=0;i<this.length;i++){
      if(this[i]===a){
        return true
      }
      }
      return false 
    }
      // console.log(arr.myIncludes(8));




    //手写every
    Array.prototype.myEvery=function(fn){
      for(let i=0;i<this.length;i++){
    if(!fn(this[i],i.array)) return false
      }
      return true
    }
    // console.log(arr.myEvery(item=>{
    //   return item>8
    // }));


    //手写some
    Array.prototype.my

  </script>
</body>
</html>